home *** CD-ROM | disk | FTP | other *** search
/ Dynamic HTML Construction Kit / Dynamic HTML Construction Kit.iso / earthlink / nscomm / java40.jar / netscape / applet / IntTable.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-11-03  |  1.7 KB  |  105 lines

  1. package netscape.applet;
  2.  
  3. class IntTable {
  4.    int count = 0;
  5.    int[] keys = new int[8];
  6.    Object[] values = new Object[8];
  7.  
  8.    public IntTable() {
  9.    }
  10.  
  11.    public int count() {
  12.       return this.count;
  13.    }
  14.  
  15.    public int keyAt(int var1) {
  16.       if (var1 >= this.count) {
  17.          throw new ArrayIndexOutOfBoundsException(var1 + " >= " + this.count);
  18.       } else {
  19.          return this.keys[var1];
  20.       }
  21.    }
  22.  
  23.    public Object elementAt(int var1) {
  24.       if (var1 >= this.count) {
  25.          throw new ArrayIndexOutOfBoundsException(var1 + " >= " + this.count);
  26.       } else {
  27.          return this.values[var1];
  28.       }
  29.    }
  30.  
  31.    public int indexOfKey(int var1) {
  32.       int var3 = this.count;
  33.  
  34.       for(int var2 = 0; var2 < var3; ++var2) {
  35.          if (this.keys[var2] == var1) {
  36.             return var2;
  37.          }
  38.       }
  39.  
  40.       return -1;
  41.    }
  42.  
  43.    public int indexOfValue(Object var1) {
  44.       int var3 = this.count;
  45.  
  46.       for(int var2 = 0; var2 < var3; ++var2) {
  47.          if (this.values[var2].equals(var1)) {
  48.             return var2;
  49.          }
  50.       }
  51.  
  52.       return -1;
  53.    }
  54.  
  55.    public Object get(int var1) {
  56.       int var2 = this.indexOfKey(var1);
  57.       return var2 < 0 ? null : this.elementAt(var2);
  58.    }
  59.  
  60.    public Object put(int var1, Object var2) {
  61.       Object var3 = this.remove(var1);
  62.       this.ensureCapacity(this.count + 1);
  63.       this.keys[this.count] = var1;
  64.       this.values[this.count] = var2;
  65.       ++this.count;
  66.       return var3;
  67.    }
  68.  
  69.    public Object remove(int var1) {
  70.       int var2 = this.indexOfKey(var1);
  71.       if (var2 < 0) {
  72.          return null;
  73.       } else {
  74.          Object var4 = this.values[var2];
  75.          int var3 = this.count - var2 - 1;
  76.          if (var3 > 0) {
  77.             System.arraycopy(this.keys, var2 + 1, this.keys, var2, var3);
  78.             System.arraycopy(this.values, var2 + 1, this.values, var2, var3);
  79.          }
  80.  
  81.          --this.count;
  82.          this.keys[var2] = 0;
  83.          this.values[var2] = null;
  84.          return var4;
  85.       }
  86.    }
  87.  
  88.    public void ensureCapacity(int var1) {
  89.       if (this.keys.length < var1) {
  90.          int var2 = this.keys.length * 2;
  91.          if (var2 < var1) {
  92.             var2 = var1;
  93.          }
  94.  
  95.          int[] var3 = new int[var2];
  96.          Object[] var4 = new Object[var2];
  97.          System.arraycopy(this.keys, 0, var3, 0, this.count);
  98.          System.arraycopy(this.values, 0, var4, 0, this.count);
  99.          this.keys = var3;
  100.          this.values = var4;
  101.       }
  102.  
  103.    }
  104. }
  105.